package com.tuanzi.loan.business.repository.banana.impl;

import com.tuanzi.loan.business.repository.banana.LoanBananaBindCardActionRepository;
import com.tuanzi.loan.business.repository.banana.custom.LoanBananaBindCardActionRepositoryCustom;
import com.tuanzi.loan.core.repository.JOOQBaseRepositoryPlus;
import com.tuanzi.loan.generated.jooq.loan.tables.LoanBananaBindCardAction;
import com.tuanzi.loan.vo.request.banana.LoanBananaBindCardActionRequest;
import com.tuanzi.loan.vo.response.banana.LoanBananaBindCardActionResponse;
import org.jooq.impl.TableImpl;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;

import static com.tuanzi.loan.generated.jooq.loan.tables.LoanBananaBindCardAction.LOAN_BANANA_BIND_CARD_ACTION;

/**
 * @author administrator
 * @createTime 2019-06-13 19:39
 */
public class LoanBananaBindCardActionRepositoryImpl extends JOOQBaseRepositoryPlus implements LoanBananaBindCardActionRepositoryCustom {
    @Override
    protected TableImpl getTable() {
        return LOAN_BANANA_BIND_CARD_ACTION;
    }

    @Override
    public Page<LoanBananaBindCardActionResponse> list(LoanBananaBindCardActionRequest searchRequest, Pageable pageable) {
        String actionId = searchRequest.getActionId();
        Integer actionType = searchRequest.getActionType();
        fields(LOAN_BANANA_BIND_CARD_ACTION.fields());
        eq(LOAN_BANANA_BIND_CARD_ACTION.ACTION_ID,actionId);
        eq(LOAN_BANANA_BIND_CARD_ACTION.ACTION_TYPE,actionType);

        return search(pageable, e->{
            LoanBananaBindCardActionResponse response = new LoanBananaBindCardActionResponse();
            response.setId(e.get(LOAN_BANANA_BIND_CARD_ACTION.ID));
            response.setActionId(e.get(LOAN_BANANA_BIND_CARD_ACTION.ACTION_ID));
            response.setAction(e.get(LOAN_BANANA_BIND_CARD_ACTION.ACTION));
            response.setActionType(e.get(LOAN_BANANA_BIND_CARD_ACTION.ACTION_TYPE));
            response.setRemark(e.get(LOAN_BANANA_BIND_CARD_ACTION.REMARK));
            response.setCreator(e.get(LOAN_BANANA_BIND_CARD_ACTION.CREATOR));
            response.setCreateTime(e.get(LOAN_BANANA_BIND_CARD_ACTION.CREATE_TIME));
            response.setUpdator(e.get(LOAN_BANANA_BIND_CARD_ACTION.UPDATOR));
            response.setUpdateTime(e.get(LOAN_BANANA_BIND_CARD_ACTION.UPDATE_TIME));
            return response;
        });
    }
}
